# encoding:UTF-8

'''
2017-6-3 pylint format
'''
# ----------------------------------------------------------------------------
# Log extends
# ----------------------------------------------------------------------------
# 创建framework对应的logger
import logging


class Dlog(object):
    '''
    注意handler的使用 rootlogger默认是没有handler的 知道真正调用输出的时候判断有没有handler
    如果没有直接就创建一个Handler放在handlers的第一个位置 作为默认输出的handler
    '''
    _logger = None

    @classmethod
    def inc(cls):
        '''inc实例'''
        if cls._logger is None:
            cls._logger = logging.getLogger()
            sthan = logging.StreamHandler()
            formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s ---> %(message)s')
            sthan.setFormatter(formatter)
            cls._logger.addHandler(sthan)
            logging.getLogger().removeHandler(cls.inc().handlers[0])
        return cls._logger

    @classmethod
    def i(cls, *argv):
        '''DLog info'''
        cls.inc().info(*argv)

    @classmethod
    def d(cls, *argv):
        '''DLog debug'''
        cls.inc().debug(*argv)

    @classmethod
    def e(cls, *argv):
        #
        '''DLog error'''
        cls.inc().error(*argv)


# 格式化打印字典
def dumpdic(tardic):
    '''format log dict'''
    import json
    strdump = json.dumps(tardic, sort_keys=True, indent=4)
    print strdump


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    Dlog.i("aa")
